﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XQ.WeChatOfficialAccount.DAL.DAL
{
    
    public class MenuDal:BaseDal<Sys_Menus>
    {
        private WeChatOfficialAccountEntities ce;

        public List<Sys_Menus> GetPartentMenuses()
        {
            using (ce=new WeChatOfficialAccountEntities())
            {
                return ce.Sys_Menus.Where(n => n.ParentID == null).OrderBy(n => n.Sortnum).ToList();
            }
        }

        public List<Sys_Menus> GetSubMenuses(int pid)
        {
            using (ce = new WeChatOfficialAccountEntities())
            {
                return ce.Sys_Menus.Where(n => n.ParentID == pid).OrderBy(n => n.Sortnum).ToList();
            }
        }

        /// <summary>
        /// 根据菜单ID获取菜单详情
        /// </summary>
        /// <param name="id">菜单ID</param>
        /// <returns></returns>
        public Sys_Menus GetMenuByID(int id)
        {
            using (ce = new WeChatOfficialAccountEntities())
            {
                return ce.Sys_Menus.FirstOrDefault(m => m.ID == id);
            }
        }
    }

    

}
